﻿using System;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Collections;
using System.Drawing;
using System.Windows.Forms;
using C1.Win.C1Command;
using C1.Win.C1List;
using C1.C1Report;
using C1.Win.C1Input;

using PCSComProduct.Items.BO;
using PCSComProduct.Items.DS;
using PCSComUtils.PCSExc;
using PCSComUtils.Common;
using PCSUtils.Log;
using PCSUtils.Utils;
using PCSComUtils.Common.BO;
using PCSProduct.STDCost;

namespace PCSProduct.Items
{
    public partial class ViewImage : Form
    {
        private const string THIS = "PCSProduct.Items.ViewImage";
        public string strPathImage = "";
        public Bitmap mPicture;
        int iHeight = 0;
        int iWeight = 0;
        public ViewImage()
        {
            InitializeComponent();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void ViewImages()
        {
                   
                const string METHOD_NAME = THIS + ".ViewImages()";
                try
                {
                    if (strPathImage.Trim() != "")
                    {
                        
                        Image img = Image.FromFile(strPathImage);
                        this.Width = img.Size.Width + 32;
                        this.Height = img.Size.Height + 70;
                        picCategory.Width = img.Size.Width;
                        picCategory.Height = img.Size.Height;
                        iHeight = img.Size.Height;
                        iWeight = img.Size.Width;
                        if (img.Size.Width > picCategory.Size.Width ||
                            img.Size.Height > picCategory.Size.Height)
                            picCategory.SizeMode = PictureBoxSizeMode.StretchImage;
                        else
                            picCategory.SizeMode = PictureBoxSizeMode.CenterImage;
                        picCategory.Image = Image.FromFile(strPathImage);
                    }
                    else
                    {
                        if (mPicture != null)
                        {
                            this.Width = mPicture.Size.Width + 32;
                            this.Height = mPicture.Size.Height + 70;
                            picCategory.Width = mPicture.Size.Width;
                            picCategory.Height = mPicture.Size.Height;
                            picCategory.Image = mPicture;
                            iHeight = mPicture.Size.Height;
                            iWeight = mPicture.Size.Width;
                        }
           
                    }
                }
                catch (Exception ex)
                {
                    PCSMessageBox.Show(ErrorCode.OTHER_ERROR);
                    try
                    {
                        Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                    }
                    catch
                    {
                        PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION);
                    }
                }
            
        }
        private void ViewImage_Load(object sender, EventArgs e)
        {
            ViewImages();
            this.CenterToScreen();
        }

        private void btnView_Click(object sender, EventArgs e)
        {
            
            int ioldWeight = iWeight;
            iWeight = iWeight ;
            try
            {
                iWeight += Convert.ToInt32(txtRoom.Text.Trim());
            }
            catch
            { }
            iHeight = (iWeight * picCategory.Height) / ioldWeight;
            this.Width = iWeight + 32;
            this.Height = iHeight + 70;
            picCategory.Size = new Size(iWeight, iHeight);
            picCategory.SizeMode = PictureBoxSizeMode.Zoom;
            this.Invalidate();
            this.CenterToScreen();
        }

        private void btnViewAm_Click(object sender, EventArgs e)
        {
            int ioldWeight = iWeight;
            iWeight = iWeight;
            try
            {
                iWeight -= Convert.ToInt32(txtRoom.Text.Trim());
            }
            catch
            { }
            iHeight = (iWeight * picCategory.Height) / ioldWeight;
            this.Width = iWeight + 32;
            this.Height = iHeight + 70;
            picCategory.Size = new Size(iWeight, iHeight);
            picCategory.SizeMode = PictureBoxSizeMode.Zoom;
            this.Invalidate();
            this.CenterToScreen();
        }

        private void btnView_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Up)
            {
                int ioldWeight = iWeight;
                iWeight = iWeight;
                try
                {
                    iWeight = +Convert.ToInt32(txtRoom.Text.Trim());
                }
                catch
                { }
                iHeight = (iWeight * picCategory.Height) / ioldWeight;
                this.Width = iWeight + 32;
                this.Height = iHeight + 70;
                picCategory.Width = iWeight;
                picCategory.Height = iHeight;
                this.CenterToScreen();
            }
        }

        private void btnViewAm_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Down)
            {
                int ioldWeight = iWeight;
                iWeight = iWeight;
                try
                {
                    iWeight = -Convert.ToInt32(txtRoom.Text.Trim());
                }
                catch
                { }
                iHeight = (iWeight * picCategory.Height) / ioldWeight;
                this.Width = iWeight + 32;
                this.Height = iHeight + 70;
                picCategory.Width = iWeight;
                picCategory.Height = iHeight;
                this.CenterToScreen();
            }
        }

        private void txtRoom_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Up)
            {
                
                int ioldWeight = iWeight;
                iWeight = iWeight;
                try
                {
                    iWeight += Convert.ToInt32(txtRoom.Text.Trim());
                }
                catch
                { }
                iHeight = (iWeight * picCategory.Height) / ioldWeight;
                this.Width = iWeight + 32;
                this.Height = iHeight + 70;
               // picCategory.Width = iWeight;
               // picCategory.Height = iHeight;
                
                picCategory.Size = new Size(iWeight, iHeight);
                picCategory.SizeMode = PictureBoxSizeMode.Zoom;
                this.Invalidate();
                this.CenterToScreen();
            }
            if (e.KeyCode == Keys.Down)
            {
                int ioldWeight = iWeight;
                iWeight = iWeight;
                try
                {
                    iWeight -= Convert.ToInt32(txtRoom.Text.Trim());
                }
                catch
                { }
                iHeight = (iWeight * picCategory.Height) / ioldWeight;
                this.Width = iWeight + 32;
                this.Height = iHeight + 70;
                picCategory.Size = new Size(iWeight, iHeight);
                picCategory.SizeMode = PictureBoxSizeMode.Zoom;
                this.Invalidate();
                this.CenterToScreen();
            }
        }
    }
}
